package tptecnicas.logging;

import java.util.ArrayList;
import java.util.List;

/**
 * Clase encargada de administrar las distintas instancias
 * de los loggers.
 */
public class LogTool {
	
	private static LogTool instance = null; 
	private List<Logger> loggers;
	
	private LogTool(){
		this.loggers = new ArrayList<>();
	}
	
	private static void createInstance() {
		if (instance == null) {
			instance = new LogTool();
		}
	}
	
	public static LogTool getLogTool() {
		createInstance();
		return instance;
	}
	
	public Logger getLogger(String name){
		for (Logger logger : loggers) {
			
			if (logger.getLoggerName().equals(name)) {
				return logger;
			}
		}
		Logger newLogger = new LoggerManager(name);
		loggers.add(newLogger);
		return newLogger;
	}	
}